package app.controller.msgmanage;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 这是一个单例，用于存放已经被同意的机柜锁和机房锁的开门请求
 * @author zhouchao
 *2017-10-25 10:11:25
 */
public class DeviceCache {
	
	private DeviceCache(){};
	
	private Map<String, Long> cacheMap = new ConcurrentHashMap();
	
	
	private static final DeviceCache deviceCache = new DeviceCache();
	
	public static DeviceCache getInstance(){
		return deviceCache;
	}
	
	public void newWait4Open(String devCode){
		cacheMap.put(devCode, System.currentTimeMillis()+3*60*1000L);
	}
	
	public boolean canBeOpen(String devCode){
		if (cacheMap.containsKey(devCode)) {
			boolean can = (System.currentTimeMillis() - cacheMap.get(devCode) <= 0);
			if (can) {
				return true;
			}
		}
		return false;
	}
	public void del(String devCode){
		cacheMap.remove(devCode);
	}
}
